package com.franklin.ideaplugin.mybatisrunner.xml.node;

import com.intellij.psi.xml.XmlElement;
import com.intellij.psi.xml.XmlTag;
import com.intellij.psi.xml.XmlText;
import lombok.Getter;
import lombok.RequiredArgsConstructor;

import java.util.Arrays;
import java.util.Map;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * @author Ye Junhui
 * @since 2024/2/21
 */
@RequiredArgsConstructor
@Getter
public enum XmlElementProcessors {

    /**
     * 本文
     */
    XML_TEXT(
            XmlText.class
    ),
    /**
     * 标签
     */
    XML_TAG(
            XmlTag.class
    ),
    ;

    /**
     * 元素类型
     */
    private final Class<? extends XmlElement> elementType;


    /**
     * 执行
     * @param xmlElement
     */
    public static void process(XmlElement xmlElement, Consumer<XmlElement> handler){
        for (XmlElementProcessors xmlElementProcessor : values()) {
            if (xmlElementProcessor.getElementType().isInstance(xmlElement)){
                handler.accept(xmlElement);
            }
        }
    }
}
